﻿Public Class xtf_LISTADOconfig_interfaz_
    Public Overrides Sub IniciarLista()
        Try
            gdc_general.BeginUpdate()
            gdc_general.DataSource = dtt_DataTable
            'ulg_Lista.DisplayLayout.GroupByBox.Style = Infragistics.Win.UltraWinGrid.GroupByBoxStyle.Full

            'Creacion y carga de Cuentas
            dtt_DataTable.Columns.Add("Identificador (ID)")
            dtt_DataTable.Columns.Add("Nombre")

            gdv_general.PopulateColumns(dtt_DataTable)

            Dim obj_config_interfaz_ As New cls_config_interfaz_
            If obj_config_interfaz_.CargarTodos(ObtenerRegistroEstado) Then
                For Each config_interfaz As cls_config_interfaz_ In obj_config_interfaz_.Items
                    AgregarItem(config_interfaz)
                Next
            End If
            'ulg_Lista.DataBind()

            FiltrarColumnas()
            gdc_general.EndUpdate()
        Catch ex As Exception
            'Dim frmError As New frm_ErrorManager(ex.Message)
        End Try
    End Sub

    Public Function AgregarItem(ByRef config_interfaz As cls_config_interfaz_) As DataRow
        Dim Row As DataRow = dtt_DataTable.NewRow
        Row("Identificador (ID)") = config_interfaz.idconfig_interfaz
        Row("Nombre") = config_interfaz.nombre

        dtt_DataTable.Rows.Add(Row)
        'ulg_Lista.Rows(ulg_Lista.Rows.Count - 1).Height = 19
        Return Row
    End Function

    Public Sub ModificarItem(ByRef config_interfaz As cls_config_interfaz_, ByRef ulg_row As DataRow)
        ulg_row("Identificador (ID)") = config_interfaz.idconfig_interfaz
        ulg_row("Nombre") = config_interfaz.nombre
    End Sub

    Public Sub New()

        Me.Cursor = Cursors.WaitCursor
        InitializeComponent()
        PERMISONuevo = "007013002"
        PERMISOModificar = "007013003"
        PERMISOEliminar = "007013004"
        PERMISOImprimir = "007013005"
        Me.Text = lbl_modulo.Text : lbl_modulodescripcion.Text = "Listado de " & lbl_modulo.Text & "."
        IniciarLista()
        Me.Cursor = Cursors.Default

    End Sub



    Public Overrides Sub bbi_Nuevo_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
        If ComprobarPermiso(PERMISONuevo) Then
            bsi_estado.Caption = "Cargando..."
            Application.DoEvents()
            Dim ABM As Object
            ABM = CType(Activator.CreateInstance(Type.GetType(Replace(Application.ProductName, " ", "_") & "." & Strings.Left(Replace(Me.Name, "xtf_LISTADO", "xtf_ABM"), Replace(Me.Name, "xtf_LISTADO", "xtf_ABM").Length - 1), True, True)), Form)
            ABM.Nuevo(Me)
            ABM.ControlarModificaciones(ABM.lac_general.items)
            ABM.showdialog()
            bsi_estado.Caption = "Listo"
        End If
        Strings.Left(Replace(Me.Name, "xtf_LISTADO", "xtf_ABM"), Replace(Me.Name, "xtf_LISTADO", "xtf_ABM").Length - 2)
    End Sub

    Public Overrides Sub bbi_Modificar_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
        If ComprobarPermiso(PERMISOModificar) Then
            Try
                Dim barrio As Object 'New cls_barrio_
                barrio = Activator.CreateInstance(Type.GetType(Replace(Application.ProductName, " ", "_") & "." & Replace(Me.Name, "xtf_LISTADO", "cls_"), True, True))
                If gdv_general.SelectedRowsCount > 0 Then
                    If barrio.Buscar(gdv_general.GetDataRow(gdv_general.GetSelectedRows(0))("Identificador (ID)")) Then
                        bsi_estado.Caption = "Cargando..."
                        Application.DoEvents()
                        Dim ABM As Object 'New xtf_ABMbarrio
                        ABM = CType(Activator.CreateInstance(Type.GetType(Replace(Application.ProductName, " ", "_") & "." & Strings.Left(Replace(Me.Name, "xtf_LISTADO", "xtf_ABM"), Replace(Me.Name, "xtf_LISTADO", "xtf_ABM").Length - 1), True, True)), Form)
                        ABM.Modificar(barrio, Me, gdv_general.GetDataRow(gdv_general.GetSelectedRows(0)))
                        ABM.ControlarModificaciones(ABM.lac_general.items)
                        ABM.showdialog()

                      
                        bsi_estado.Caption = "Listo"
                    End If
                End If

            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
    End Sub

    Public Overrides Sub bbi_Eliminar_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
        If ComprobarPermiso(PERMISOEliminar) Then
            Try
                If gdv_general.SelectedRowsCount > 0 Then
                    If ErrManagerShow("000005", Me) = DialogResult.Yes Then
                        Dim eliminarRegistro As Boolean = False
                        If UsuarioLOG.esroot Then
                            If ErrManagerShow("001023", Me) = DialogResult.Yes Then
                                eliminarRegistro = True
                            End If
                        End If


                        Dim objeto As Object
                        objeto = Activator.CreateInstance(Type.GetType(Replace(Application.ProductName, " ", "_") & "." & Replace(Me.Name, "xtf_LISTADO", "cls_"), True, True))


                        objeto.Eliminar(gdv_general.GetDataRow(gdv_general.GetSelectedRows(0))("Identificador (ID)"))

                        dtt_DataTable.Rows.Remove(gdv_general.GetDataRow(gdv_general.GetSelectedRows(0)))
                    End If
                End If
            Catch ex As Exception
                'Dim frmError As New frm_ErrorManager(ex.Message)
            End Try
        End If

    End Sub
End Class
